spa.model = (function($){
    var
        configMap = {
            roles_db : TAFFY(),
            grids : TAFFY()
        },User,Grid

    User = (function(){
        var
            loginComplete,login,initModule,getDb

        getDb = function(){
            return configMap.roles_db
        }


        loginComplete = function(result){
            for(index in result){
                configMap.roles_db.insert(result[index])
            }
            $.gevent.publish(spa.events.spaEventLogin,[result])
        },

        login = function(options){
            spa.data.on(spa.events.spaEventLogin,loginComplete)
            spa.data.emit(spa.events.spaEventLogin,options)
        }
        return {
            login:login,
            getDb : getDb
        }
    }())

    Grid = (function(){
        var
            getGrid,getGridComplete,getDb

        getDb = function(){
            return configMap.grids
        }
        getGridComplete = function(result){
            var index,params
            result = eval(result)

            configMap.grids.insert(result)

            $.gevent.publish(spa.events.spaEventGrid,result)
        }

        getGrid = function(options){
            spa.data.on(spa.events.spaEventGrid,getGridComplete)
            spa.data.emit(spa.events.spaEventGrid,options)
        }
        return {
            getDb : getDb,
            getGrid : getGrid
        }
    }())

    return {
        User : User,
        Grid : Grid
    }

}(jQuery))